//
//  uXwooCJLCFMineSettingViewControllerAUjeby.m
//  qcb_ios
//
//  Created by Ji on 2018/8/30.
//  Copyright © 2018年 ski. All rights reserved.
//

#import "uXwooCJLCFMineSettingViewControllerAUjeby.h"
#import "sHkPtEJLCFMineRequestozAYZs.h"
#import "kWnxeXJLCFMineSettingInfoCellhODGKD.h"
#import "trfPXRJLCFMineSettingAmountCellYeIGoq.h"
#import "bpXPwZJLCFMineSettingDataModelhmSxqV.h"
#import "bNmycrJLCFMineSettingChangePasswordControllerXFCPIY.h"
#import "OsrffmJLCFMineBankCardViewControllerUidVai.h"
#import "empwxzJLCFMineAddressListViewControllerTeFNdn.h"

@interface uXwooCJLCFMineSettingViewControllerAUjeby ()

@property (nonatomic, strong) bpXPwZJLCFMineSettingDataModelhmSxqV *data;

@end

@implementation uXwooCJLCFMineSettingViewControllerAUjeby

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self addNavigationBar];
    self.navigationBar.title = @"安全设置";
    
    self.view.backgroundColor = QTZ_Gray237;
    
    UIView *footerBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, FULL_WIDTH, 40)];
    UIButton *logoutBtn = [[UIButton alloc] initWithFrame:CGRectMake(38, 0, FULL_WIDTH - 76, 40)];
    [logoutBtn setTitle:@"退出登录" forState:0];
    [logoutBtn setBackgroundColor:QTZ_White];
    logoutBtn.titleLabel.font = FONT(15);
    [logoutBtn setTitleColor:Theme_Color forState:0];
    [logoutBtn addTarget:self action:@selector(handleLogout) forControlEvents:UIControlEventTouchUpInside];
    logoutBtn.layer.cornerRadius = 5;
    [footerBgView addSubview:logoutBtn];
    self.tableView.tableFooterView = footerBgView;
    
    self.tableView.mj_header.hidden = YES;
    self.tableView.mj_footer.hidden = YES;
    [self loadData];
    
}

- (void)loadData
{
    
    [sHkPtEJLCFMineRequestozAYZs settingWithParams:nil loadingInView:self.view success:^(bpXPwZJLCFMineSettingDataModelhmSxqV *data) {
        
        self.data = data;
        [self.tableView reloadData];
        
    } failure:^(NSString *error) {
        [self showNotice:error];
    }];
    
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    } else {
        return 3;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 38;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 0) {
        trfPXRJLCFMineSettingAmountCellYeIGoq *cell = [trfPXRJLCFMineSettingAmountCellYeIGoq dequeueReusableCellForTableView:tableView];
        cell.phone = self.phone;
        [cell reloadData];
        return cell;
    } else {
        kWnxeXJLCFMineSettingInfoCellhODGKD *cell = [kWnxeXJLCFMineSettingInfoCellhODGKD dequeueReusableCellForTableView:tableView];
        [cell setWithIndexPath:indexPath];
        cell.flFGIcbindCardmirovY = self.data.type;
        [cell reloadData];
        return cell;
    }
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 1) {
        if (indexPath.row == 0) {//修改密码
            bNmycrJLCFMineSettingChangePasswordControllerXFCPIY *vc = [bNmycrJLCFMineSettingChangePasswordControllerXFCPIY new];
            vc.phone = self.phone;
            [[[JinLiCaiFuApplicationEntrace shareEntrance] currentNavController] pushViewController:vc animated:YES];
        } else if (indexPath.row == 1) {//我的银行卡
            OsrffmJLCFMineBankCardViewControllerUidVai *vc = [OsrffmJLCFMineBankCardViewControllerUidVai new];
            vc.bindComplete = ^{
                [self loadData];
            };
            [[[JinLiCaiFuApplicationEntrace shareEntrance] currentNavController] pushViewController:vc animated:YES];
        } else if (indexPath.row == 2) {//收货地址
            [[[JinLiCaiFuApplicationEntrace shareEntrance] currentNavController] pushViewController:[MineAddressgUCAmcJLCFListViewControllernRoqhZ new] animated:YES];
        }
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, FULL_WIDTH, 5)];
    footerView.backgroundColor = [UIColor clearColor];
    return footerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 0) {
        return 5;
    } else {
        return 30;
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *rRHNlxheaderViewfJQeRl = [[UIView alloc] initWithFrame:CGRectMake(0, 0, FULL_WIDTH, 15)];
    rRHNlxheaderViewfJQeRl.backgroundColor = [UIColor clearColor];
    return rRHNlxheaderViewfJQeRl;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 15;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    
        if ([cell respondsToSelector:@selector(tintColor)]) {
            
            if (tableView == self.tableView) {
                
                CGFloat cornerRadius = 10.f;
                
                cell.backgroundColor = UIColor.clearColor;
                
                CAShapeLayer *layer = [[CAShapeLayer alloc] init];
                
                CGMutablePathRef pathRef = CGPathCreateMutable();
                
                CGRect bounds = CGRectInset(cell.bounds, 10, 0);
                
                if (indexPath.row == 0 && indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
                    
                    CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius);
                    
                } else if (indexPath.row == 0) {
                    
                    CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds));
                    
                    CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);
                    
                    CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
                    
                    CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));
                    
                } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
                    
                    CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));
                    
                    CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
                    
                    CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
                    
                    CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));
                    
                } else {
                    
                    CGPathAddRect(pathRef, nil, bounds);
                    
                }
                
                layer.path = pathRef;
                
                CFRelease(pathRef);
                
                layer.fillColor = [UIColor colorWithWhite:1.f alpha:1.f].CGColor;
                
                
                UIView *testView = [[UIView alloc] initWithFrame:bounds];
                
                [testView.layer insertSublayer:layer atIndex:0];
                
                testView.backgroundColor = UIColor.clearColor;
                
                cell.backgroundView = testView;
                
            }
            
        }
        
}

- (void)handleLogout
{
    
    [[JLCFRegisterService shareService] logOut];
    if (self.LogoutComplete) {
        self.LogoutComplete();
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
